﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Administrator_SanPham : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!Page.IsPostBack)
        //{
        //    this.ddthuonghieu1.SelectedIndex = 0;
        //    this.ddLoai1.SelectedIndex = 0;
        //    this.ddLoai1.Enabled = false;
        //    this.ddchucnang1.SelectedIndex = 0;
        //    this.ddchucnang1.Enabled = false;
        //    this.NhanHieu2.FilterExpression=""
        //    //this.GridView1.DataSource = this.NhanHieu2;
        //    this.GridView1.DataBind();
        //}
    }
    protected void ddthuonghieu1_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.ddLoai1.Items.Clear();
        this.ddLoai1.Items.Add(new ListItem("All", "-1"));
        if (this.ddthuonghieu1.SelectedIndex == 0)
        {
            this.ddLoai1.SelectedIndex = 0;
            this.ddLoai1.Enabled = false;
            this.ddchucnang1.SelectedIndex = 0;
            this.ddchucnang1.Enabled = false;
            //this.GridView1.DataSource = this.NhanHieu2;
        }
        else
        {
            this.ddLoai1.Enabled = true;
            if (this.ddLoai1.SelectedIndex == 0)
            {
                this.NhanHieu2.FilterExpression = "NhanHieuID = " + this.ddthuonghieu1.SelectedValue;
                //this.NhanHieu2.FilterParameters.Add("NhanHieuID", System.Data.DbType.Int32, this.ddthuonghieu1.SelectedValue);
                //this.GridView1.DataSource = Loai2;
            }
            else
                if (this.ddchucnang1.SelectedIndex == 0)
                {
                    this.NhanHieu2.FilterExpression = "NhanHieuID ="+this.ddthuonghieu1.SelectedValue+" and LoaiID="+ this.ddLoai1.SelectedValue;
                    
                    //this.GridView1.DataSource = ChucNang2;
                }
                else
                {

                    this.NhanHieu2.FilterExpression = "NhanHieuID =" + this.ddthuonghieu1.SelectedValue + " and LoaiID=" + this.ddLoai1.SelectedValue + " and ChucNangID=" + this.ddchucnang1.SelectedValue;
                     
                    //this.GridView1.DataSource = this.SqlDataSource1;
                }
        }
        this.GridView1.DataBind();
    }
    protected void ddLoai1_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.ddchucnang1.Items.Clear();
        this.ddchucnang1.Items.Add(new ListItem("All", "-1"));
        if (this.ddLoai1.SelectedIndex == 0)
        {
            this.ddchucnang1.SelectedIndex = 0;
            this.ddchucnang1.Enabled = false;

            this.NhanHieu2.FilterExpression = "NhanHieuID =" + this.ddthuonghieu1.SelectedValue;
            //this.GridView1.DataSource = Loai2;
        }
        else
            if (this.ddchucnang1.SelectedIndex == 0)
            {
                this.ddchucnang1.Enabled = true;
                //this.GridView1.DataBind();
                this.NhanHieu2.FilterExpression = "NhanHieuID =" + this.ddthuonghieu1.SelectedValue + " and LoaiID=" + this.ddLoai1.SelectedValue;
                    
                //this.GridView1.DataSource = this.ChucNang2;
            }
            else
            {

                this.NhanHieu2.FilterExpression = "NhanHieuID =" + this.ddthuonghieu1.SelectedValue + " and LoaiID=" + this.ddLoai1.SelectedValue + " and ChucNangID=" + this.ddchucnang1.SelectedValue;
                   
                //this.GridView1.DataSource = this.SqlDataSource1;
            }
        this.GridView1.DataBind();
    }
    protected void ddchucnang1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.ddchucnang1.SelectedIndex == 0)
        {

            this.NhanHieu2.FilterExpression = "NhanHieuID =" + this.ddthuonghieu1.SelectedValue + " and LoaiID=" + this.ddLoai1.SelectedValue;
                   
            //this.GridView1.DataSource = ChucNang2;
        }
        else
        {

            this.NhanHieu2.FilterExpression = "NhanHieuID =" + this.ddthuonghieu1.SelectedValue + " and LoaiID=" + this.ddLoai1.SelectedValue + " and ChucNangID=" + this.ddchucnang1.SelectedValue;
            //this.GridView1.DataSource = this.SqlDataSource1;
        }
        this.GridView1.DataBind();
    }
    
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        status();
    }
    public void status()
    {
        if (this.ddthuonghieu1.SelectedIndex == 0)
        {
            this.ddLoai1.SelectedIndex = 0;
            this.ddLoai1.Enabled = false;
            this.ddchucnang1.SelectedIndex = 0;
            this.ddchucnang1.Enabled = false;
            //this.GridView1.DataSource = this.NhanHieu2;
        }
        else
        {
            this.ddLoai1.Enabled = true;
            if (this.ddLoai1.SelectedIndex == 0)
            {
                this.NhanHieu2.FilterExpression = "NhanHieuID = " + this.ddthuonghieu1.SelectedValue;
                //this.NhanHieu2.FilterParameters.Add("NhanHieuID", System.Data.DbType.Int32, this.ddthuonghieu1.SelectedValue);
                //this.GridView1.DataSource = Loai2;
            }
            else
                if (this.ddchucnang1.SelectedIndex == 0)
                {
                    this.NhanHieu2.FilterExpression = "NhanHieuID =" + this.ddthuonghieu1.SelectedValue + " and LoaiID=" + this.ddLoai1.SelectedValue;

                    //this.GridView1.DataSource = ChucNang2;
                }
                else
                {

                    this.NhanHieu2.FilterExpression = "NhanHieuID =" + this.ddthuonghieu1.SelectedValue + " and LoaiID=" + this.ddLoai1.SelectedValue + " and ChucNangID=" + this.ddchucnang1.SelectedValue;

                    //this.GridView1.DataSource = this.SqlDataSource1;
                }
        }
        this.GridView1.DataBind();
    }

}


